'''# Third_party'''
from openpyxl.styles import *
from openpyxl.utils import *


'''# ↓↓↓单条用例步骤测试结果单元格生成逻辑↓↓↓'''
def fieldWrite(ws, ws_column_max, ws_rows_max):
    """
     参数：
        @param ws : sheet表对象
        @param ws_column_max : 表格最大列值
        @param ws_rows_max : 表格最大行值
    """
    fieldList = {}  # 存放sheet表中的所有字段名
    for i in range(1, ws_column_max+1):
        fieldList[ws.cell(row=1, column=i).value] = i

    if f'测试结果' in fieldList:  # 判断字段名是否存在
        return fieldList[f'测试结果']
        
    else:
        # 预设单元格格式
        thin = Side(border_style="thin", color="000000")  # 边框样式
        border = Border(left=thin, right=thin, top=thin, bottom=thin)
        fill = PatternFill(patternType="solid", start_color="92d050")  # 填充样式
        align = Alignment(horizontal='center',vertical='center',wrap_text=True)  # 对齐方式

        # 循环进行设置
        for column in range(ws_column_max+1, ws_column_max+3):
            ws.column_dimensions[get_column_letter(column)].width = 20  # 列宽
            for row in range(1, ws_rows_max+1):
                ws.cell(row=row, column=column).border = border
                ws.cell(row=row, column=column).alignment = align
                if row == 1 :
                    ws.cell(row=row, column=column).fill = fill
                else:
                    pass
    
        # 字段名信息写入
        ws.cell(row=1, column=ws_column_max+1).value = '测试结果'
        ws.cell(row=1, column=ws_column_max+2).value = '错误信息'

        return ws_column_max+1